﻿#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>

//查找输入整数二进制中1的个数
//https://www.nowcoder.com/questionTerminal/1b46eb4cf3fa49b9965ac3c2c1caf5ad
//int main() {
//    int num = 0;
//    while (cin >> num)
//    {
//        int count = 0;
//        while (num)
//        {
//            if (num % 2) { ++count; }
//            num /= 2;
//        }
//        cout << count << endl;
//    }
//}

//手套
//https://www.nowcoder.com/questionTerminal/365d5722fff640a0b6684391153e58d8
class Gloves {
public:
    int findMinimum(int n, vector<int> left, vector<int> right) {
        int suml = 0, sumr = 0; //左右手套都存在的数量的和
        int minl = INT_MAX, minr = INT_MAX; //左右手套都存在的数量的最小值,初始化为最大值
        int single = 0;
        for (int i = 0; i < n; ++i)
        {
            if (!left[i] || !right[i]) //统计左右手套单只总数
            {   //当一个为0就计入总数
                single += left[i] + right[i]; //不知道是左右哪一个手套为0全部计入
            }
            else
            {
                suml += left[i];
                sumr += right[i];
                minl = min(minl, left[i]);
                minr = min(minr, right[i]);
            }
        }
        return single + min(suml - minl + 1, sumr - minr + 1) + 1;
    }
};

int main()
{
    Gloves g;
   
    cout << g.findMinimum(5, vector<int>{3,4,0,6,7}, vector<int>{7,9,2,0,4}) << endl;
    return 0;
}